home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 March / Chip_2002-03_cd1.bin / zkuste / delphi / kompon / d3456 / EHS.ZIP / setup.exe / {app} / ehstcard.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-04-19  |  5.2 KB  |  167 lines

  1. { TTrainingCard
  2.  
  3.   Delphi 3/4/5/6 Implementation for Winhelp training card help.
  4.  
  5.   ⌐ 2000-2001 EC Software. All rights reserved.
  6.  
  7.   This product and it's source code is protected by patents, copyright laws and
  8.   international copyright treaties, as well as other intellectual property
  9.   laws and treaties. The product is licensed, not sold.
  10.  
  11.   The source code and sample programs in this package or parts hereof
  12.   as well as the documentation shall not be copied, modified or redistributed
  13.   without permission, explicit or implied, of the author.
  14.  
  15.  
  16.   EMail: info@ec-software.com
  17.   Internet: http://www.ec-software.com
  18.  
  19.   Disclaimer of Warranty
  20.   ----------------------
  21.  
  22.   THIS SOFTWARE AND THE ACCOMPANYING FILES ARE PROVIDED "AS IS" AND
  23.   WITHOUT WARRANTIES OF ANY KIND WHETHER EXPRESSED OR IMPLIED.
  24.  
  25.   In no event shall the author be held liable for any damages whatsoever,
  26.   including without limitation, damages for loss of business profits,
  27.   business interruption, loss of business information, or any other loss
  28.   arising from the use or inability to use the software. }
  29.  
  30. unit ehstcard;
  31.  
  32. interface
  33.  
  34. uses
  35.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
  36.  
  37. type
  38.   TTrainingCardButtonEvent = procedure(Sender : TObject; Button: word) of object;
  39.   TTrainingCardDataEvent = procedure(Sender : TObject; Data: integer) of object;
  40.  
  41.   TTrainingCard = class(TComponent)
  42.   private
  43.      fWindowHandle: HWND;
  44.      fHelpFile: string;
  45.      fIsActive: boolean;
  46.      fOnCardData: TTrainingCardDataEvent;
  47.      fOnButton: TTrainingCardButtonEvent;
  48.      fOnClose: TNotifyEvent;
  49.      fOnOtherCaller: TNotifyEvent;
  50.      procedure SetHelpFile(newfile: string);
  51.      procedure TrainingCardEvent(Action, Data: integer);
  52.   protected
  53.      procedure WndProc(var Message: TMessage);
  54.   public
  55.     constructor Create(AOwner: TComponent); override;
  56.     destructor  Destroy; override;
  57.     procedure   Close;
  58.     function    HelpCommand(Command: Word; Data: Longint): Boolean;
  59.     function    HelpContext(Context: THelpContext): Boolean;
  60.     function    HelpJump(const JumpID: string): Boolean;
  61.     property    IsActive: boolean read fIsActive;
  62.   published
  63.     property HelpFile: string read fHelpFile write SetHelpFile;
  64.     property OnCardData: TTrainingCardDataEvent read fOnCardData write fOnCardData;
  65.     property OnButton: TTrainingCardButtonEvent read fOnButton write fOnButton;
  66.     property OnClose: TNotifyEvent read fOnClose write fOnClose;
  67.     property OnOtherCaller: TNotifyEvent read fOnOtherCaller write fOnOtherCaller;
  68.   end;
  69.  
  70. implementation
  71.  
  72. constructor TTrainingCard.Create(AOwner: TComponent);
  73. begin
  74.      inherited;
  75.      fWindowHandle := 0;
  76.      fIsActive := false;
  77. end;
  78.  
  79. destructor TTrainingCard.Destroy;
  80. begin
  81.      if fIsActive then Close;
  82.      inherited;
  83. end;
  84.  
  85. procedure TTrainingCard.SetHelpFile(newfile: string);
  86. begin
  87.      if fIsActive then Close;
  88.      fHelpFile := newfile;
  89. end;
  90.  
  91. procedure TTrainingCard.WndProc(var Message: TMessage);
  92. begin
  93.      with Message do
  94.      begin
  95.           if msg = WM_TCARD then TrainingCardEvent(wparam, lparam)
  96.           else DefWindowProc(fWindowHandle, msg, wparam, lparam);
  97.      end;
  98. end;
  99.  
  100. procedure TTrainingCard.TrainingCardEvent(Action, Data: integer);
  101. begin
  102.      case Action of
  103.      HELP_TCARD_DATA: if assigned(fOnCardData) then fOnCardData(self, Data);
  104.  
  105.      IDABORT, IDCANCEL,
  106.      IDHELP, IDIGNORE,
  107.      IDOK, IDNO,
  108.      IDRETRY, IDYES: if assigned(fOnButton) then fOnButton(self, Action);
  109.  
  110. { fIsActive is true when the user has closed the training card.
  111.   It is false if we closed it programmatically with TTrainingCard.Close }
  112.  
  113.      IDCLOSE: if fIsActive then
  114.               begin
  115.                 if assigned(fOnClose) then fOnClose(self);
  116.                 Close;
  117.               end;
  118.      HELP_TCARD_OTHER_CALLER:
  119.        begin
  120.             if assigned(fOnOtherCaller) then fOnOtherCaller(self);
  121.             Close;
  122.        end;
  123.      end;
  124. end;
  125.  
  126. function TTrainingCard.HelpCommand(Command: Word; Data: Longint): Boolean;
  127. begin
  128.      result := false;
  129.      if (fHelpFile <> '') then
  130.      begin
  131.           if (not fIsActive) and (Command <> HELP_QUIT) then fWindowHandle := AllocateHwnd(WndProc);
  132.           fIsActive := (Command <> HELP_QUIT) and (fWindowHandle <> 0);
  133.           if fIsActive then
  134.           begin
  135.                WinHelp(fWindowHandle, PChar(fHelpFile), HELP_FORCEFILE + HELP_TCARD, 0);
  136.                result := WinHelp(fWindowHandle, PChar(fHelpFile), Command + HELP_TCARD, Data);
  137.           end;
  138.      end;
  139. end;
  140.  
  141. function TTrainingCard.HelpJump(const JumpID: string): Boolean;
  142. var
  143.   Command: array[0..255] of Char;
  144. begin
  145.   StrLFmt(Command, SizeOf(Command) - 1, 'JumpID("","%s")', [JumpID]);
  146.   result := HelpCommand(HELP_COMMAND, Longint(@Command));
  147. end;
  148.  
  149. function TTrainingCard.HelpContext(Context: THelpContext): Boolean;
  150. begin
  151.   result := HelpCommand(HELP_CONTEXT, Context);
  152. end;
  153.  
  154. procedure TTrainingCard.Close;
  155. begin
  156.      if fWindowHandle <> 0 then
  157.      begin
  158.           WinHelp(fWindowHandle, PChar(fHelpFile), HELP_QUIT + HELP_TCARD, 0);
  159.           DeAllocateHwnd(fWindowHandle);
  160.           fWindowHandle := 0;
  161.           fIsActive := false;
  162.      end;
  163.      Application.HelpCommand(HELP_QUIT, 0);
  164. end;
  165.  
  166. end.
  167.